Page({
  data: {
    arr: ['wxml', 'js', 'wxss', 'json'],
    obj: [
      { name: 'wxml' },
      { name: 'js' },
      { name: 'wxss' },
      { name: 'json' }
    ]
  },
  handleRandom() {
    const length = this.data.arr.length
    for (let i = 0; i < length; i++) {
      const x = Math.floor(Math.random() * length)
      const y = Math.floor(Math.random() * length)
      const temp = this.data.arr[x]
      this.data.arr[x] = this.data.arr[y]
      this.data.arr[y] = temp
    }

    this.setData({
      arr: this.data.arr
    })
  },
  handleRandomObj() {
    const length = this.data.obj.length
    for (let i = 0; i < length; i++) {
      const x = Math.floor(Math.random() * length)
      const y = Math.floor(Math.random() * length)
      const temp = this.data.obj[x]
      this.data.obj[x] = this.data.obj[y]
      this.data.obj[y] = temp
    }

    this.setData({
      obj: this.data.obj
    })
  }
})